﻿/*
 * Rappelz: Endless Odyssey - The first free open source Rappelz server emulator
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 */

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Rappelz.GameServer
{
    public class Globals
    {
        public static int nRegionSize = 150;

        public static readonly DateTime StartOfEpoch = new DateTime(1970, 1, 1);
        static MersenneTwister randomGen = new MersenneTwister(Environment.TickCount);
        private static object rndLock = new object();

        public static int GetRandomInt32()
        {
            lock(rndLock)
            {
                return (int)randomGen.NextUInt32();
            }
        }

        public static uint GetRandomUInt32()
        {
            lock (rndLock)
            {
                return randomGen.NextUInt32();
            }
        }


        public static int GetRandomInt32(int _min, int _max)
        {
            lock(rndLock)
            {
                return (int)randomGen.Next(_min, _max);
            }
        }

        public static uint GetArTime()
        {
            return (uint) Environment.TickCount / 10;
        }
        public static long GetUnixTimestampInt64()
        {
            return (long)(DateTime.UtcNow - StartOfEpoch).TotalMilliseconds;
        }
        public static ulong GetUnixTimestampUInt64()
        {
            return (ulong)(DateTime.UtcNow - StartOfEpoch).TotalMilliseconds;
        }

        public static DateTime GetDateTimeFromUnixTimestamp(long t)
        {
            return StartOfEpoch.AddMilliseconds(t);
        }

        public static long Time64()
        {
            DateTime dtn = DateTime.UtcNow;
            long t64 = dtn.Ticks;
            t64 -= StartOfEpoch.Ticks;
            t64 /= 10000000L;
            return t64;
        }


        public static String AppPath;

        static public XLog Log;
        static public XLog CommandLog;
    }
}
